﻿var createBtn=function(text,click){
	var b=document.createElement('button');
	b.innerHTML=text;
	b.onclick=click;
	document.body.appendChild(b);
}


createBtn('delSelectedRows',function(){
	var keys=grid.getSelectedKeys();
	if(keys.length){
		grid.delRow(keys);
	}
});
var ac=1;
createBtn('add',function(){
	grid.addRow({
		name:'Tom'+ac,
		age:45,
		height:168,
		sex:0,
		desc:'Tom'+ac+' is a teacher'
	});
	ac++;
});
var grid;
Mui.use('Mui.util.Grid',function(Mui){
	grid=new Mui.util.Grid({
		title:'Grid',
		style:'margin:10px',
		hasColl:true,
		hasRefresh:true,
		// height:300,
		columns:[{
			field:'name',
			width:100,
			header:'name',
			sortable:true
		},{
			field:'sex',
			width:60,
			header:'sex',
			renderer:function(val){
				return val?'女':'男';
			},
			sortable:true
		},{
			field:'age',
			width:80,
			header:'age',
			renderer:function(val){
				return val+' years'
			},
			sortable:true
		},{
			field:'desc',
			header:'desc',
			width:300,
			sortable:true
		}],
		rows:[{
			name:'Lucy',
			age:20,
			height:168,
			sex:1,
			desc:'lucy is a beautiful girl'
		},{
			name:'Lily',
			age:20,
			height:168,
			sex:1,
			desc:'Lily is Lucy\'s sister,also a beautiful girl'
		},{
			name:'Mark',
			age:22,
			height:175,
			sex:0,
			desc:'Mark is Lusy\'s classmate'
		},{
			name:'John',
			age:24,
			height:170,
			sex:0,
			desc:'John is Mark\'s brother'
		}]
	});

});



